package cn.hquanheng.java_base;

import java.util.Arrays;

import org.junit.Test;

public class Example {
	@Test
	public void text() {
		int a = 3;
		int b = 4;
		// 从堆（heap）内存里面申请一块空间
		int[] array = { 5, 6 };
		int[] arrays = { 7, 8, 9, 0 };
		changeInt(a, b);
		changeArray(array);
		changeArrays(arrays);
		System.out.println(a + " " + b);
		System.out.println(Arrays.toString(array));
		System.out.println(Arrays.toString(arrays));
		inInputArray(array);
		System.out.println(Arrays.toString(array));
	}

	public static void changeInt(int x, int y) {
		int temp = x;
		x = y;
		y = temp;
	}

	public static void changeArray(int[] array) {
		int temp = array[0];
		array[0] = array[1];
		array[1] = temp;
	}

	public static void changeArrays(int[] arrays) {
		for (int i = 0; i < arrays.length / 2; i++) {
			int temp = arrays[i];
			arrays[i] = arrays[arrays.length - i - 1];
			arrays[arrays.length - i - 1] = temp;
		}
	}

	public static void inInputArray(int[] array) {
		array = new int[1];
		array[0] = 8;
	}
	@Test
	public void text02() {
		int x=8;int y=10;
		System.out.println(gcd(x,y));
		System.out.println(gcd(y,x));
		System.out.println(gcd(y,y));
		}
	public static int gcd(int x, int y){
	    //辗转相除法
	    int z;//商
	    z=x%y;
	    while(z!=0){
	        x=y;
	        y=z;
	        z=x%y;
	    }
	    return y;
	}
	@Test
	public void text03() {
		breakCir();
	}
	public static void breakCir() {
		for(int i=0;i<2;i++) {
			System.out.print("i ");
			for(int j=0;j<2;j++) {
				System.out.print("j ");
				for(int k=0;k<2;k++) {
					System.out.print("k ");
				}
			}
		}
	System.out.println();
	System.out.println("//===break====i//");
	ii:
	for(int i=0;i<2;i++) {
		System.out.print("i ");
		for(int j=0;j<2;j++) {
			System.out.print("j ");
			for(int k=0;k<2;k++) {
				System.out.print("k ");
				break ii;
			}
		}
	}
	System.out.println();
	System.out.println("//===break====j//");
	for(int i=0;i<2;i++) {
		System.out.print("i ");
		jj:
		for(int j=0;j<2;j++) {
			System.out.print("j ");
			for(int k=0;k<2;k++) {
				System.out.print("k ");
				break jj;
			}
		}
	}
	System.out.println();
	System.out.println("//===break====k//");
	for(int i=0;i<2;i++) {
		System.out.print("i ");
		for(int j=0;j<2;j++) {
			System.out.print("j ");
			kk:
			for(int k=0;k<2;k++) {
				System.out.print("k ");
				break;
			}
		}
	}
	}
}
